fix: add ETag caching to UpdateChecker to avoid GitHub rate limits - #115
Merged
Conversation
Two problems caused the HTTP 403 Update check failed error: 1. No conditional request caching: every update check consumed one of GitHub's 60 unauthenticated requests/hour per IP. On shared networks (NAT, VPN, office) the pool is easily exhausted. Fixed by persisting the ETag from each 200 response and sending it as If-None-Match on subsequent requests. GitHub returns 304 Not Modified when the release hasn't changed — 304s are rate-limit free and served from CDN edge. 2. Bare User-Agent: 'VocaMac' instead of 'VocaMac/<version>'. GitHub recommends including the app version to help them identify clients. Fixed to 'VocaMac/0.5.0' (resolved at runtime from bundle). Caching strategy: - On 200 OK: persist ETag and raw JSON body to UserDefaults - On 304 Not Modified: decode and return the cached JSON body - On 304 with missing cache (UserDefaults cleared): evict ETag and surface an error so the next check gets a fresh 200 response - ETag and cache body are keyed separately so they can be cleared independently (e.g. ETag eviction on cache miss)
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every launch logs:
Root Causes
1. No conditional request caching
Every update check consumed one of GitHub's 60 unauthenticated requests/hour per IP. On shared networks (NAT, VPN, office, CI runners) the pool is trivially exhausted — especially since the nightly build CI also hits the same API.
2. Bare User-Agent string
The request sent
User-Agent: VocaMacinstead ofUser-Agent: VocaMac/0.5.0. GitHub recommends including the app version so they can identify and contact clients that misbehave.Fix
ETag conditional caching:
ETagresponse header and raw JSON body toUserDefaultsIf-None-Match: <cached-etag>Versioned User-Agent:
VocaMac/<bundle-version>resolved at runtime.Result
Testing
All 163 tests pass.